package com.bl.student.api.controller.order;

import com.bl.student.api.controller.BaseController;
import com.bl.student.common.ApiResponseBody;
//import com.bl.student.service.biz.ico.IcoService;
import com.bl.student.service.biz.order.OrderService;
//import com.bl.student.service.vo.ico.IcoListVo;
import com.bl.student.service.vo.order.OrderListVo;
import com.bl.student.service.vo.order.OrderVoListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by liangweikang on 18/12/26.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/apis/order"})
@Api(value = "订单相关api", description = "订单相关api")
public class OrderController extends BaseController{

    @Autowired
    OrderService orderService;

    @ApiOperation(value = "我的订单列表", notes = "我的订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "0 未发货 1已发货", required = false, paramType = "query", dataType = "status", defaultValue = "0"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<OrderVoListVo> orderList(
            @RequestParam(value = "status", required = false, defaultValue = "1") String status,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        OrderVoListVo orderVoListVo = orderService.getListByUser(pageable, getUserInfo(request).getId(), status);

        return ApiResponseBody.createSuccessBody(orderVoListVo);
    }
}
